import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutterapp2/building/buildinfo.dart';
import 'package:flutterapp2/model/base_response.dart';
import 'package:flutterapp2/model/person.dart';
import 'package:flutterapp2/model/test_bean.dart';
import 'package:flutterapp2/model/test_bean2.dart';
import 'package:flutterapp2/model/test_info.dart';
import 'package:flutterapp2/extension/extension.dart';
import 'package:flutterapp2/model/test_safe_parse.dart';
import 'package:flutterapp2/test/test_bean_1.dart';
import 'package:flutterapp2/test/test_bean_2.dart';
import 'package:fluttertoast/fluttertoast.dart';

/// 解析结果最终回调
typedef CallBack = void Function({dynamic data, String error});

/// 获取对象的回调函数

class TestParsePage extends StatefulWidget {
  @override
  _TestParsePageState createState() => _TestParsePageState();
}

class _TestParsePageState extends State<TestParsePage> {
  BaseResponse data;

  @override
  void initState() {
    super.initState();
    rootBundle.loadString('assets/files/data.json').then((value) {
      var result = BaseResponse.fromJson(jsonDecode(value));
//      var projectDetailModelBean = ProjectDetailModelBean.fromJson(result.data);
      var bean = TestSafeParseBean.fromJson(result.data);
      print("object");
    });
//    var person = Person(code: "110");
//    var p2 = person.copyWith();
//    List<Person> list = List();
//    list.add(person);
//    person.code = "100";
//    print(person == p2);
//    AgentResult agentResult;
//    var empty = agentResult?.student?.name.isNullOrEmpty;
//    String text;
//    print("$empty");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("测试json解析"),
      ),
      body: Container(
        height: 200,
        padding: EdgeInsets.all(12),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              width: 100,
              height: 100,
              color: Colors.blue,
            ),
            Text(
              "听说可以很长" * 4,
              overflow: TextOverflow.ellipsis,
            ).expanded(),
          ],
        ).click(() => Fluttertoast.showToast(msg: "haha")),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {},
        tooltip: 'Increment',
        child: new Icon(Icons.add),
      ),
    );
  }
}
